﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Caching;

namespace XCommunity.Frames
{
  public class TopicMetaCache : CacheContainer
  {


    public TopicMetaCache( FrameService service )
    {
      _service = service;
    }


    private FrameService _service;

    /// <summary>
    /// 获取框架服务
    /// </summary>
    protected FrameService FrameService
    {
      get { return _service; }
    }


    public void AddItem( TopicMeta topicMeta )
    {
      AddItem( topicMeta.TopicId, topicMeta );
    }

    public TopicMeta GetTopicMeta( int topicId )
    {

      return (TopicMeta) TryGetValue( topicId );
    }


    public TopicMeta GetOrLoadMeta( int topicId, Func<int, TopicMeta> loader )
    {
      return GetOrLoadValue( topicId, loader );
    }



    public void RemoveCacheItem( int topicId )
    {
      base.RemoveCacheItem( topicId );
    }


    private long spanTicks = new TimeSpan( 0, 5, 0 ).Ticks;


    public override bool CheckAvailable( CacheItem cacheItem )
    {
      return Service.GetTime().Ticks <= cacheItem.RefreshTime.Ticks + spanTicks;
    }



  }
}
